﻿#ifndef C3FDSOLVECONTROLWIDGET_H
#define C3FDSOLVECONTROLWIDGET_H

#include <QWidget>
#include <QProcess>
#include <QTreeWidgetItem>
#include "Common/C3fdProject.h"
#include "Common/C3fdCase.h"

namespace Ui
{
	class C3fdSolveControlWidget;
}

namespace MainWidget
{
	class C3fdSolveControlWidget : public QWidget
	{
		Q_OBJECT

	public:
		explicit C3fdSolveControlWidget(QTreeWidgetItem *item, bool isFirst, QWidget *parent = nullptr);
		~C3fdSolveControlWidget();

	signals:
		void updateLineChart(QString);
		void sendMessage(QString);

	public slots:
		void on_dsb_RotationSpeed_editingFinished();
		void on_dsb_InletTemperature_editingFinished();
		void on_dsb_InletPressure_editingFinished();
		void on_dsb_InletAirflowAngle_editingFinished();
		void on_dsb_OutletPressure_editingFinished();
		void on_sb_StartRotationSpeed_editingFinished();
		void on_sb_IterativeSteps_editingFinished();
		void on_pb_Select_clicked();
		void on_pb_StartSolve_clicked();
		void on_pb_StopSolve_clicked();
		void processFinished(int, QProcess::ExitStatus);
		void readProcessOutput();
		void readAllStandardErrorSlot();

	private:
		bool copyMeshInputs(QString meshPath, QString inputPath);
		bool generateControlInput(QString inputPath);
		bool generateTbmodelInput(QString inputPath);
		bool generateBoundaryInput(QString inputPath);
		bool generatePerfCurveInput(QString inputPath);

	private:
		Ui::C3fdSolveControlWidget *m_Ui = nullptr;
		Common::C3fdProject *m_Project = nullptr;
		QProcess m_Process{};
		Common::C3fdCase *m_CurrentCase = nullptr;
		Common::WorkCondition *m_CurrentWorkCondition = nullptr;
		bool m_IsFirstWorkCondition = false;
	};
}
#endif // C3FDSOLVECONTROLWIDGET_H
